package com.yunc.base.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * 线程池配置
 *
 * @author taocongcong
 * @create 2018-10-30 14:03
 */
@Configuration
public class ExecutorConfig {

    private static int CORE_POOL_SIZE = 5;
    private static int MAX_POOL_SIZE = 1000;

    @Bean(name="taskExecutor")
    public ThreadPoolTaskExecutor taskExecutor(){
        ThreadPoolTaskExecutor poolTaskExecutor = new ThreadPoolTaskExecutor();
        // 线程池维护线程的最少数量，核心线程数
        poolTaskExecutor.setCorePoolSize(CORE_POOL_SIZE);
        // 线程池维护线程的最大数量，最大线程数
        poolTaskExecutor.setMaxPoolSize(MAX_POOL_SIZE);
        // 线程池所使用的缓冲队列，队列大小
        poolTaskExecutor.setQueueCapacity(200);
        // 线程池维护线程所允许的空闲时间
        poolTaskExecutor.setKeepAliveSeconds(30000);
        poolTaskExecutor.setWaitForTasksToCompleteOnShutdown(true);
        return poolTaskExecutor;
    }
}
